<?php

	include("common.php");
	
	$result = mysql_query("SELECT * FROM `197_albums`");
	$albums = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($albums, $row);
	}
	
?>
<?php include("header.php"); ?>
<h1>修改／刪除相簿</h1>
<div id="delete-album-dialog">
	<p>確定刪除？</p>
</div>
<script type="text/javascript" src="../jquery/js/jquery.tools.min.js"></script>
<script type="text/javascript" defer="defer">
	$("#delete-album-dialog").dialog({
		width: 300,
		height: 210,
		autoOpen: false,
		title: "刪除相簿",
		modal: true,
		draggable: false,
		resizable: false
	});
	function showConfirm(album_id){
		$("#delete-album-dialog").dialog("option", "buttons", {"確定": function(){ $(this).dialog("close"); deleteAlbum(album_id); }, "取消": function(){ $(this).dialog("close"); }
		}).dialog("open");
	}
	function deleteAlbum(album_id){
		$("#delete-album-dialog").dialog("option", "buttons", { "關閉": function(){ location.reload(); } });
		$("#delete-album-dialog").html("<img src='../images/ajax-loader.gif' />");
		$("#delete-album-dialog").dialog("open");
		$("#delete-album-dialog").load("albumDelete.php?album_id=" + album_id + "&ajax=true");
	}
	
	$(function(){
		$("#album-list a[title]").tooltip({

			// a little tweaking of the position
			offset: [10, 10],

			// use the built-in fadeIn/fadeOut effect
			effect: 'slide',
			slideOffset: 5,
			direction: 'top',

			// custom opacity setting
			opacity: 10,
			
			tipClass: "text-tooltip"
		});
	});
	
</script>
<link rel="stylesheet" href="../jquery/css/text-tooltip.css" />
<?php if(empty($albums)){ ?>
	<p>目前沒有相簿。</p>
<?php } else { ?>
	<ul id="album-list">
		<?php foreach($albums as $row){ ?>
			<li><a href="#" title="<?php echo htmlspecialchars($row['description']); ?><br /><small>[ <a href='albumEdit.php?album_id=<?php echo $row['album_id']; ?>'>編輯</a>｜<a href='albumDelete.php?album_id=<?php echo $row['album_id']; ?>' onclick='showConfirm(<?php echo $row['album_id']; ?>); return false;'>刪除</a>｜<a href='imageUpload.php?album_id=<?php echo $row['album_id']; ?>'>上傳</a>｜<a href='imageList.php?album_id=<?php echo $row['album_id']; ?>'>列表</a> ]</small>"><?php echo $row['title']; ?></a></li>
		<?php } ?>
	</ul>
<?php } ?>
<p><button class="custom" onclick="location.replace('albumAdd.php');">新增相簿</button></p>
<?php include("sidebar.php"); ?>
<?php include("footer.php"); ?>